import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';
import {release} from '../../../utils/api'
let app = getApp()
Page({
  data: {
    src: '',
    projectDto:{
      "content": null,
      "title": null,
      "userId": null,
    },
    size:0,
    switch2Checked: false,
  },
  //选择视频
  chooseVideo: function() {
    var that = this
    wx.chooseVideo({
      sourceType:['album','camera'],
      camera:'back',
      success: function(res) {
        that.setData({
          src: res.tempFilePath,
          size: (res.size / (1024 * 1024)).toFixed(2)
        })
       
      }
    })
  },
  deleteVideo: function(event){
    let src = [this.data.src]
    src.splice(0, 1)
    this.setData({
      src
    })
  },
  uploadvideo: function() {
    let src = this.data.src;
    let TOKEN = wx.getStorageSync('TOKEN')  
    let projectDto = this.data.projectDto
    console.log(src);
    console.log(this.data.size);
    wx.uploadFile({
      url: app.globalData.ip+'/project/release',
      filePath: src,
      name: 'file',
      method:'POST',
      header: {
        'content-type':'multipart/form-data',
        'Authorization':TOKEN
      },
      success: function(res) {
        console.log('sucess',res)
      },
      fail: function() {
        console.log('接口调用失败')
      }
    })
  },
  content(e){
    let content = this.data.projectDto
    content.content = e.detail.value
    this.setData({
      projectDto: content
    })
  },
  toAddTag:function(){
    // this.uploadvideo();
    Dialog.confirm({
      title: '提示',
      message: '你的项目已创建，是否为项目生成标签？',
    })
      .then(() => {
        wx.navigateTo({
          url: '../addTag/addTag',
        })
      })
      .catch(() => {
        wx.switchTab({
          url: '../add/add',
        })
      });
  },
  onChange(event) {
    // event.detail 为当前输入的值
    // console.log(event.detail);
    let title = this.data.projectDto
    title.title = event.detail
    this.setData({
      projectDto:title
    })
  },
  onClick(event) {
    var flag = !this.data.flag
    this.setData({
      flag
    });
    console.log(flag);
  
  },
  onLoad:function(){
    let userId = wx.getStorageSync('userId');
    let projectDto = this.data.projectDto;
    projectDto.userId = userId;
  }


})
